Skip to content

chore: upgrade#1789

Merged
shunkakinoki merged 1 commit into
mainfrom
chore/upgrade
May 17, 2026
Merged

chore: upgrade#1789
shunkakinoki merged 1 commit into
mainfrom
chore/upgrade

Conversation

@shunkakinoki
Copy link
Copy Markdown
Owner

@shunkakinoki shunkakinoki commented May 15, 2026

Automated upgrade

@shunkakinoki shunkakinoki enabled auto-merge (squash) May 15, 2026 13:38
@indent
Copy link
Copy Markdown
Contributor

indent Bot commented May 15, 2026

PR Summary

Automated re-sync of config/{claude,codex}/hooks/rtk-rewrite.sh from upstream rtk-ai/rtk via scripts/sync-rtk-rewrite.sh. Upstream narrowed the hook's scope to Claude Code's PreToolUse:Bash only, so this PR drops the multi-platform input parsing and Copilot-shaped output that #1788 had added locally one PR ago, without updating the downstream Copilot wiring or test specs.

  • Input parsing collapses from 7 fallback selectors (.tool.input, .tool_input, .toolArgs object/string, .toolInput, .command) to just .tool_input.command // empty.
  • ORIGINAL_INPUT simplified to read .tool_input directly (no more string→fromjson coercion or {} fallback).
  • Removes the IS_COPILOT_INPUT branch and the {permissionDecision, modifiedArgs} output shape; the script now always emits the Claude-Code hookSpecificOutput envelope.
  • Header docstring narrowed from "Claude/Codex/Copilot PreToolUse shell commands" to "Claude Code PreToolUse:Bash".
  • Claude and Codex copies remain byte-identical (preserves the spec/sync_rtk_rewrite_spec.sh invariant).

Issues

2 potential issues found:

  • shell-check CI is red because the sync didn't update the Copilot tests landed in feat: add Copilot and Codex hook parity #1788spec/rtk_rewrite_spec.sh:113-128 and spec/codex_rtk_rewrite_spec.sh:67-81 still assert that .modifiedArgs.command is populated for {toolName, toolArgs} payloads, but the rewritten hook no longer emits modifiedArgs, producing 4 failures in shell-test. Update or delete those specs as part of this PR (paired with the Copilot wiring decision in the other issue) so the required check goes green. → Autofix
  • Copilot's RTK rewrite hook is silently broken after this sync — config/copilot/default.nix still installs config/codex/hooks/rtk-rewrite.sh as ~/.copilot/hooks/rtk-rewrite.sh and config/copilot/config.json still calls it, but the new script only reads .tool_input.command so Copilot's {toolName, toolArgs} payload yields an empty CMD and no-ops. Either restore the Copilot input/output branches in the codex copy, or remove the Copilot wiring under config/copilot/ and the Copilot test cases together so the sync stays self-consistent. → Autofix

CI Checks

Same 4 shellspec failures as on prior SHAs — shell-test remains red on the Copilot modifiedArgs cases added in #1788. The recent force-pushes are rebase-only and don't touch the hooks or specs, so the failure mode is identical across runs. Same root cause as the open 'Copilot's RTK rewrite hook is silently broken' issue.

Failing shell-check / shell-test→ Autofix
  • 4 shellspec failures, identical to prior runs: spec/rtk_rewrite_spec.sh:113,121 and spec/codex_rtk_rewrite_spec.sh:67,75 — the rewrites Copilot {object,string} toolArgs with modifiedArgs output cases. The hook no longer emits .modifiedArgs.command, so jq -r '.modifiedArgs.command' returns empty and the output should include 'rtk' assertion fails. Same root cause as the open 'Copilot's RTK rewrite hook is silently broken' issue; the recent force-pushes are rebase-only and don't touch the hooks or specs.

⚡ Autofix All

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 74fc39b6-abfb-4bbb-95b5-54c3795d3ceb

📥 Commits

Reviewing files that changed from the base of the PR and between 4d66d9c and dea933e.

📒 Files selected for processing (2)
  • config/claude/hooks/rtk-rewrite.sh
  • config/codex/hooks/rtk-rewrite.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/claude/hooks/rtk-rewrite.sh
  • config/codex/hooks/rtk-rewrite.sh

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Unified tool input interpretation so rewrite logic consistently reads a single command input shape.
    • Standardized rewrite output behavior: certain rewrites now trigger an explicit "ask for clarification" path, while other rewrites are returned as allowed with a brief permission reason.
    • Removed a previous special-case branch for a tool-specific input shape, simplifying hook behavior and payload construction.

Walkthrough

Two RTK auto-rewrite hook scripts (config/claude/hooks/rtk-rewrite.sh and config/codex/hooks/rtk-rewrite.sh) are refactored to extract the command only from .tool_input.command, remove historical fallback parsing, construct ORIGINAL_INPUT from .tool_input, update .command with the rewrite result, and unify output branching to depend solely on EXIT_CODE.

Changes

RTK Hook Unified Input/Output Refactoring

Layer / File(s) Summary
Hook identification and scope clarification
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Header comments updated to identify the scripts as the RTK auto-rewrite hook for "Claude Code PreToolUse:Bash".
Command input extraction simplification
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Both hooks now extract CMD via a single jq lookup of .tool_input.command, removing multi-path fallback logic for other input shapes.
Unified output payload and branching
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Rewritten payloads now set ORIGINAL_INPUT from .tool_input, overwrite only the command field with the rewritten value, and choose output format based solely on EXIT_CODE, removing prior Copilot-specific branching and alternate permissionDecision/modifiedArgs structures.

🎯 2 (Simple) | ⏱️ ~12 minutes

"I nibbled old fallbacks down to none,
One jq hop, two hooks, and now it's done.
Commands flow tidy, outputs aligned—
A rabbit's small refactor, neat and kind. 🐇"

Sequence diagram (high-level flow):

sequenceDiagram
  participant HookScript
  participant RTK as rtk_rewrite
  participant OutputRouter
  participant Client
  HookScript->>RTK: send CMD from .tool_input.command
  RTK-->>HookScript: REWRITTEN command + EXIT_CODE
  HookScript->>OutputRouter: build UPDATED_INPUT (ORIGINAL_INPUT + .command = REWRITTEN)
  OutputRouter->>Client: emit hookSpecificOutput (varies by EXIT_CODE)
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore: upgrade' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific changes to the RTK rewrite hooks. Use a more specific title that describes the actual changes, such as 'refactor: simplify RTK rewrite hooks command extraction and output routing' or similar.
Description check ❓ Inconclusive The description 'Automated upgrade' is too vague and generic, providing no meaningful information about what was changed or why in the RTK hook modifications. Provide a more detailed description explaining the refactoring of command extraction logic and output routing changes in both hook files.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/upgrade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the rtk-rewrite.sh hooks for Claude and Codex to focus on Claude Code PreToolUse:Bash. The changes significantly simplify the command extraction and input processing logic by removing support for multiple input formats (such as .toolArgs and .tool.input) and eliminating GitHub Copilot-specific output structures. Feedback highlights that these changes introduce regressions, including data loss for metadata in certain input structures and broken compatibility with GitHub Copilot integrations.

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This simplified command extraction logic removes support for multiple input formats used by GitHub Copilot and other integrations (e.g., .toolArgs, .tool.input, and stringified JSON in toolArgs). This regression will cause the hook to skip rewrites for these platforms and will break existing tests in spec/rtk_rewrite_spec.sh (lines 113-128). To maintain robustness and consistency, ensure the logic follows established patterns for Nix-extracted scripts and uses unique delimiters with read and IFS for any command output parsing.

References
  1. To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and read with a matching IFS. This is safer than splitting by spaces with cut, especially when data fields might contain spaces.
  2. Maintain consistency with established patterns for writing scripts that are extracted from Nix expressions, even if it involves suppressing linter warnings like ShellCheck SC2024.

) | if type == "string" then (fromjson? // {}) else . end
')
# Build the updated tool_input with all original fields preserved, only command changed.
ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Restricting ORIGINAL_INPUT to only the .tool_input object leads to data loss for other supported input structures. Previously, the script ensured that all original fields (such as timeout or other metadata) were preserved regardless of the input format.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of the IS_COPILOT_INPUT check and the specific modifiedArgs output format breaks compatibility with GitHub Copilot. Copilot requires this specific JSON structure to accept and execute the rewritten command; without it, the rewrite functionality will be ignored by the Copilot client.

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This simplified command extraction logic removes support for multiple input formats used by GitHub Copilot and other integrations (e.g., .toolArgs, .tool.input, and stringified JSON in toolArgs). This regression will cause the hook to skip rewrites for these platforms and will break existing tests in spec/codex_rtk_rewrite_spec.sh (lines 67-81). To maintain robustness and consistency, ensure the logic follows established patterns for Nix-extracted scripts and uses unique delimiters with read and IFS for any command output parsing.

References
  1. To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and read with a matching IFS. This is safer than splitting by spaces with cut, especially when data fields might contain spaces.
  2. Maintain consistency with established patterns for writing scripts that are extracted from Nix expressions, even if it involves suppressing linter warnings like ShellCheck SC2024.

) | if type == "string" then (fromjson? // {}) else . end
')
# Build the updated tool_input with all original fields preserved, only command changed.
ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Restricting ORIGINAL_INPUT to only the .tool_input object leads to data loss for other supported input structures. Previously, the script ensured that all original fields (such as timeout or other metadata) were preserved regardless of the input format.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of the IS_COPILOT_INPUT check and the specific modifiedArgs output format breaks compatibility with GitHub Copilot. Copilot requires this specific JSON structure to accept and execute the rewritten command; without it, the rewrite functionality will be ignored by the Copilot client.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="config/claude/hooks/rtk-rewrite.sh">

<violation number="1" location="config/claude/hooks/rtk-rewrite.sh:35">
P1: Parsing only `.tool_input.command` breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.</violation>

<violation number="2" location="config/claude/hooks/rtk-rewrite.sh:85">
P1: Removing the Copilot output path breaks integrations that expect `modifiedArgs` responses instead of Claude `hookSpecificOutput`.</violation>
</file>

<file name="config/codex/hooks/rtk-rewrite.sh">

<violation number="1" location="config/codex/hooks/rtk-rewrite.sh:35">
P1: This now only reads `.tool_input.command`, so valid non-`tool_input` payloads are skipped and never rewritten.</violation>

<violation number="2" location="config/codex/hooks/rtk-rewrite.sh:85">
P1: Removing the Copilot output branch changes the response contract and drops `modifiedArgs`, breaking codex/copilot-style hook consumers.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Removing the Copilot output path breaks integrations that expect modifiedArgs responses instead of Claude hookSpecificOutput.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/claude/hooks/rtk-rewrite.sh, line 85:

<comment>Removing the Copilot output path breaks integrations that expect `modifiedArgs` responses instead of Claude `hookSpecificOutput`.</comment>

<file context>
@@ -86,37 +78,11 @@ esac
-      }'
-  fi
-elif [ "$EXIT_CODE" -eq 3 ]; then
+if [ "$EXIT_CODE" -eq 3 ]; then
   # Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
   jq -n \
</file context>

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Parsing only .tool_input.command breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/claude/hooks/rtk-rewrite.sh, line 35:

<comment>Parsing only `.tool_input.command` breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.</comment>

<file context>
@@ -32,15 +32,7 @@ fi
-  // .command
-  // empty
-')
+CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
 
 if [ -z "$CMD" ]; then
</file context>
Suggested change
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
CMD=$(echo "$INPUT" | jq -r '
.tool.input.command
// .tool_input.command
// (.toolArgs | if type == "object" then .command else empty end)
// (.toolArgs | if type == "string" then (fromjson? | .command) else empty end)
// .toolInput.command
// .command
// empty
')

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Removing the Copilot output branch changes the response contract and drops modifiedArgs, breaking codex/copilot-style hook consumers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/codex/hooks/rtk-rewrite.sh, line 85:

<comment>Removing the Copilot output branch changes the response contract and drops `modifiedArgs`, breaking codex/copilot-style hook consumers.</comment>

<file context>
@@ -86,37 +78,11 @@ esac
-      }'
-  fi
-elif [ "$EXIT_CODE" -eq 3 ]; then
+if [ "$EXIT_CODE" -eq 3 ]; then
   # Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
   jq -n \
</file context>

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This now only reads .tool_input.command, so valid non-tool_input payloads are skipped and never rewritten.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/codex/hooks/rtk-rewrite.sh, line 35:

<comment>This now only reads `.tool_input.command`, so valid non-`tool_input` payloads are skipped and never rewritten.</comment>

<file context>
@@ -32,15 +32,7 @@ fi
-  // .command
-  // empty
-')
+CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
 
 if [ -z "$CMD" ]; then
</file context>
Suggested change
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
CMD=$(echo "$INPUT" | jq -r '
.tool.input.command
// .tool_input.command
// (.toolArgs | if type == "object" then .command else empty end)
// (.toolArgs | if type == "string" then (fromjson? | .command) else empty end)
// .toolInput.command
// .command
// empty
')

@shunkakinoki shunkakinoki force-pushed the chore/upgrade branch 2 times, most recently from 417c0f7 to 9194093 Compare May 16, 2026 05:57
// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot integration is silently broken by this sync. This Codex copy is also what gets installed as Copilot's hook (config/copilot/default.nix sets home.file.".copilot/hooks/rtk-rewrite.sh".source = ../codex/hooks/rtk-rewrite.sh, and config/copilot/config.json calls $HOME/.copilot/hooks/rtk-rewrite.sh in its preToolUse array). Copilot CLI sends {"toolName":"shell","toolArgs":{"command":"..."}} (or a stringified JSON variant), but with this PR CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') returns empty for those payloads, so the hook falls through the empty-command guard and never rewrites — no error, just a silent no-op for every Copilot Bash invocation. The IS_COPILOT_INPUT/modifiedArgs output branch removed at line 85 below compounds the issue: even if CMD were extracted, Copilot expects modifiedArgs, not Claude's hookSpecificOutput. This regresses the Copilot parity work from #1788. Either re-introduce both branches here (and in the Claude copy, to keep spec/sync_rtk_rewrite_spec.sh's byte-identical invariant) — possibly with a comment to prevent the next scripts/sync-rtk-rewrite.sh run from clobbering it again — or remove the Copilot wiring (config/copilot/config.json entry + config/copilot/default.nix symlink) and the corresponding Copilot specs together.

@shunkakinoki shunkakinoki force-pushed the chore/upgrade branch 2 times, most recently from 3c9319a to 4d66d9c Compare May 16, 2026 19:26
@shunkakinoki shunkakinoki disabled auto-merge May 17, 2026 12:34
@shunkakinoki shunkakinoki merged commit 538e7e4 into main May 17, 2026
33 of 35 checks passed
@shunkakinoki shunkakinoki deleted the chore/upgrade branch May 17, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant